<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <t:base type="jquery,easyui,tools,DatePicker,ckeditor"></t:base>

    <link rel="stylesheet" href="${webRoot}/plug-in/custom_style/css/style.css"/>
    <link rel="stylesheet" href="${webRoot}/plug-in/lhgDialog/skins/blue.css"/>
    <link rel="stylesheet" href="${webRoot}/plug-in/lhgDialog/skins/default.css"/>
    <script type="text/javascript" src="${webRoot}/plug-in/ajaxfileupload/ajaxfileupload.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#homeShow").children().first().remove();

            $('#cc').combotree({
                url: 'columnsController.do?setPFunction&selfId=${topicEntity.columns.columnsId}',
                width: 155,
                onSelect: function (node) {
                    var pId = "";
                    if (node.id != "") {
                        pId = node.id;
                    }
                    $("#pId").val(pId);
                }
            });

            if ($("#cc").val() == "") {
                $('#cc').combotree('setValue', '');
            }

            //导师加载后加载导师系列
            var consultant_id = $("#creator").val();
            if (consultant_id) {
                get_FL_data();
            }

            //更新时候，如果存在视频进行显示
            initVedio();


        });


        /**
         编辑时候初始化视频显示*
         */
        function initVedio() {
            var videoUrl = $("#videoUrl").val();
            var _html = '<video width="400" height="300" controls="controls"><source id="showUrl" src="${webRoot}/' + videoUrl + '" type="video/mp4">浏览器不兼容此H5播放器</video>';
            $("#cltd").prepend(_html);
        }

        //        Ajax文件上传
        function f_file_upload(realUrl, showUrl, videoUrl) {
            var path = $("#" + realUrl).val();

            var pos1 = path.lastIndexOf("\\");
            var pos2 = path.lastIndexOf(".");

            var fileName = path.substring(pos1 + 1, pos2);

            var result = path.substring(pos2 + 1, path.length);

            var voides = ".mp4";
            //文件类型 false为压缩包
            var bool = false;
            if (voides.indexOf(result) < 0) {
                tip(" 只能上传后缀为 " + voides + " 的文件！");
                $("#" + realUrl).val("");
                return;
            }

            $.ajaxFileUpload({
                url: '${webRoot}/myFileUpload/upload_resource_voide.do',
                secureuri: false,
                fileElementId: realUrl,
                //dataType: 'json',
                success: function (data) {
                    var data2 = data.split(",");
                    var url = data2[0].replace(" ", "");
                    fileName = data2[1].replace(" ", "");

                    <%--$("#" + showUrl).attr("src", "${webRoot}/" + url);--%>

                    var _html = '<video width="400" height="300" controls="controls"><source id="showUrl" src="${webRoot}/' + url + '" type="video/mp4">浏览器不兼容此H5播放器</video>';
                    $("#cltd").prepend(_html);
//
                    $("#" + videoUrl).val(url);
                },
                error: function (data) {
                    console.log("error");
                    console.log(data);
                }
            });
        }

        function f_file_upload2(fileInputId, imgId, valueId) {
            var path = $("#" + fileInputId).val();
            var pos1 = path.lastIndexOf("\\");
            var pos2 = path.lastIndexOf(".");

            var fileName = path.substring(pos1 + 1, pos2);

            var result = path.substring(pos2 + 1, path.length);

            var imgs = ".bmp.jpg.dib.jpeg.png.jfif.jpe.tif.tiff.gif.BMP.JPG.DIB.JPEG.PNG.JFIF.JPE.TIF.TIFF.GIF";
            //文件类型 false为压缩包
            var boo = false;
            if (imgs.indexOf(result) > -1) {
                boo = true;
            } else {
                tip(" 只能上传后缀为 " + imgs + " 的文件！");
                $("#" + fileInputId).val("");
                return;
            }

            $.ajaxFileUpload({
                url: '${webRoot}/myFileUpload/uploadImageScale.do',
                secureuri: false,
                fileElementId: fileInputId,
                //dataType: 'json',
                success: function (data) {
                    var data2 = data.split(",");
                    var url = data2[0].replace(" ", "");
                    fileName = data2[1].replace(" ", "");

                    $("#" + imgId).attr("src", "${webRoot}/" + url);
                    $("#" + valueId).val(url);
                },
                error: function (data) {

                    console.log("error");
                    console.log(data);
                }
            });
        }

        /**
         * 选定咨询师后触发事件
         */
        function get_FL_data() {
            var consultant_id = $("#creator").val();
            $.post("ccourseController.do?get_consultant_fl", {consultant_id: consultant_id}, function (data) {
                $("#fl_qy").empty();
                var h = "";
                for (var i = 0; i < data.length; i++) {
                    h += "<option  value='" + data[i]['id'] + "'>" + data[i]['name'] + "</option>"
                }
                $("#fl_qy").html(h);

                //更新时候，默认选定已经选择的系列值
                var csid = $("#csid").val();

                if (csid) {
                    $("#fl_qy").val(csid);
                }
                select_XL();
            }, "json");

        }
        function select_XL() {
            var fl_qy_value = $("#fl_qy").val();
            $("#csid").val(fl_qy_value);
        }
    </script>
</head>

<body scroll="no">
<t:formvalid formid="addformobj" dialog="true" usePlugin="password" layout="table"
             action="ccourseController.do?saveorupdate_course">
    <%--实体主键--%>
    <input name="id" type="hidden" value="${entity.id}">

    <div class="new_table_list">
        <table cellpadding="0" cellspacing="1" class="formtable">
            <tbody>
            <tr>
                <th colspan="4">课程</th>
            </tr>
            <tr>
                <td align="center" style="width: 100px">
                    <label class="Validform_label">
                        导师:
                    </label>
                </td>
                <td class="txt_left value">
                    <input type="hidden" id="creator" name="consultantEntity.consultantId"
                           value="${entity.consultantEntity.consultantId}">
                    <input type="inputxt" id="showName"
                           value="${entity.consultantEntity.aCustomerEntity.realname}"
                           readonly="readonly" nullmsg='请选择咨询师' style="width: 150px;" datatype="*">
                    <t:choose name="consultantList" hiddenName="creator" hiddenid="consultantId"
                              url="consultantController.do?selectConsultantView"
                              icon="icon-search" title="选择咨询师" inputTextname="showName"
                              textname="realName" isclear="false" width="650px" height="450px"
                              fun="get_FL_data"></t:choose>
                    <span class="Validform_checktip"></span>
                </td>
            </tr>
            <tr>
                <td align="center" style="width: 100px">
                    <label class="Validform_label">
                        课程名称:
                    </label>
                </td>
                <td class="txt_left value">
                    <input class="inputxt" style="width: 250px;" name="name" value="${entity.name}" datatype="*"
                           maxlength="128">
                    <span class="Validform_checktip"></span>
                </td>
            </tr>

            <tr>
                <td align="center" style="width: 100px">
                    <label class="Validform_label">
                        系列:
                    </label>
                </td>
                <td class="txt_left value" id="fl_td">
                        <%--onchange="fz();"--%>
                    <select id="fl_qy" datatype="*" nullmsg='请选择视频系列' style="width: 250px;" onchange="select_XL()">
                    </select>
                    <input type="hidden" id="csid" name="courseSeriesEntity.id" value="${entity.courseSeriesEntity.id}">
                    <span class="Validform_checktip"></span>
                </td>
            </tr>
            <tr>
                <td align="center" style="width: 100px">
                    <label class="Validform_label">
                        栏目:
                    </label>
                </td>
                <td class="txt_left value">
                    <input hidden="hidden" id="cc" name="cc" value="${entity.columnsEntity.columnsId}">
                    <input type="hidden" id="pId" name="columnsEntity.columnsId"
                           value="${entity.columnsEntity.columnsId}"
                           datatype='*' nullmsg="请选择栏目">
                    <span class="Validform_checktip"></span>
                </td>
            </tr>
            <tr>
                <td align="left" style="width: 100px">
                    <label class="Validform_label">
                        首页展示:
                    </label>
                </td>
                <td class="txt_left value">
                    <t:dictSelect id="homeShow" field="homeShow" typeGroupCode="homeShow"
                                  defaultVal="${entity.homeShow}" hasLabel="false"></t:dictSelect>
                </td>
            </tr>
            <tr>
                <td align="center" style="width: 100px">
                    <label class="Validform_label">
                        单价:
                    </label>
                </td>
                <td class="txt_left value">
                    <input class="inputxt" style="width: 250px;" name="price" value="${entity.price}" datatype="num"
                           maxlength="128">
                    <span class="Validform_checktip"></span>
                </td>
            </tr>
            <tr>
                <td align="center" style="width: 100px">
                    <label class="Validform_label">
                        简介:
                    </label>
                </td>
                <td class="txt_left value">
                    <textarea style="width:70%;height: 150px;" name="courseIntro">${entity.courseIntro}</textarea>
                    <span class="Validform_checktip"></span>
                </td>
            </tr>
            <tr>
                <td align="center" style="width: 100px">
                    <label class="Validform_label">
                        描述:
                    </label>
                </td>
                <td class="txt_left value">
                    <textarea style="width:70%;height: 150px;" name="courseDesc">${entity.courseDesc}</textarea>
                    <span class="Validform_checktip"></span>
                </td>
            </tr>
            <tr>
                <td align="center" style="width: 100px">
                    <label class="Validform_label">
                        背景图:
                    </label>
                </td>
                <td class="txt_left value">
                    <img id="backgrounpThumbImg"
                         src='${webRoot}/${entity.backgrounp==null||bank.backgrounp==""?"upload/defCodeset.png":entity.backgrounp}'
                         class="viewimg" alt="预览" title="预览" width="400px;" height="200px;">
                    <a href="javascript:;" class="uploadimg"
                       onclick="javascript:$(this).next().trigger('click')">上传图片</a>
                    <input type="file" style="display: none;" name="file" id="backgrounp"
                           onchange="f_file_upload2('backgrounp','backgrounpThumbImg','backgrounpThumb')"/>
                    <input type="hidden" name="backgrounp" id="backgrounpThumb"
                           value='${entity.backgrounp==null?"upload/defCodeset.png":entity.backgrounp}'/>
                </td>
            </tr>
            <tr>
                <td align="center" style="width: 100px">
                    <label class="Validform_label">
                        课程视频:
                    </label>
                </td>
                <td class="txt_left value" id="cltd">
                    <a href="javascript:;" class="uploadimg"
                       onclick="javascript:$(this).next().trigger('click')">视频上传</a>
                    <input type="file" style="display: none;" name="file" id="realUrl"
                           onchange="f_file_upload('realUrl','showUrl','videoUrl')"/>
                    <input type="hidden" name="videoUrl" id="videoUrl"
                           value='${entity.videoUrl}'/>
                </td>
            </tr>
        </table>
    </div>
</t:formvalid>
</body>
</html>